#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2018-03-15 15:35:06
"""
server启动文件入口，基本不用再改动
"""

import tornado.ioloop
import tornado.options
import tornado.httpserver
from application import app
from tornado.options import define, options
try:
    import ConfigParser
except ModuleNotFoundError:
    import configparser as ConfigParser
import os


# 读取server启动的相关配置
config_file = os.path.join(os.path.dirname(__file__), "conf", "server.ini")
cfg = ConfigParser.ConfigParser()
cfg.read(config_file)
define('port', default=cfg.get('server', 'port'), help='server监听的端口')


def main():
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    print('server running on 127.0.0.1:%s' % options.port)
    print('quit server with ctrl+c')
    tornado.ioloop.IOLoop.instance().start()


if __name__ == '__main__':
    main()
